/*
 * 3.5 Implement a MyQueue class which implements a queue using two stacks.
 */
public class MyQueue {
	private Stack s1;
	private Stack s2;

	public MyQueue() {
		s1 = new Stack();
		s2 = new Stack();
	}

	public int dequeue() {
		int n = Integer.MIN_VALUE;

		if (s2.isEmpty()) {
			if (s1.isEmpty()) {
				n = Integer.MIN_VALUE;
			} else {
				while (!s1.isEmpty()) {
					s2.push(s1.pop().data);
				}
				n = s2.pop().data;
			}

		} else {
			n = s2.pop().data;
		}

		return n;
	}

	public void enqueue(int d) {
		s1.push(d);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyQueue mq = new MyQueue();

		mq.enqueue(1);
		System.out.println(mq.dequeue());
		mq.enqueue(2);
		mq.enqueue(3);
		mq.enqueue(4);
		System.out.println(mq.dequeue());
		mq.enqueue(5);
		System.out.println(mq.dequeue());
		System.out.println(mq.dequeue());
		System.out.println(mq.dequeue());
		System.out.println(mq.dequeue());
	}

}
